package com.ruoyi.web.controller.clothing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.clothing.domain.vo.querySize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.clothing.domain.SysCustomization;
import com.ruoyi.clothing.service.ISysCustomizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 定制管理Controller
 *
 * @author weh
 * @date 2024-01-20
 */
@RestController
@RequestMapping("/clothing/customization")
public class SysCustomizationController extends BaseController
{
    @Autowired
    private ISysCustomizationService sysCustomizationService;

    /**
     * 查询定制管理列表
     */
//    @PreAuthorize("@ss.hasPermi('clothing:customization:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCustomization sysCustomization)
    {
        startPage();
        List<SysCustomization> list = sysCustomizationService.selectSysCustomizationList(sysCustomization);
        return getDataTable(list);
    }

    /**
     * 导出定制管理列表
     */
//    @PreAuthorize("@ss.hasPermi('clothing:customization:export')")
    @Log(title = "定制管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCustomization sysCustomization)
    {
        List<SysCustomization> list = sysCustomizationService.selectSysCustomizationList(sysCustomization);
        ExcelUtil<SysCustomization> util = new ExcelUtil<SysCustomization>(SysCustomization.class);
        util.exportExcel(response, list, "定制管理数据");
    }

    /**
     * 获取定制管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('clothing:customization:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(sysCustomizationService.selectSysCustomizationById(id));
    }

    /**
     * 新增定制管理
     */
//    @PreAuthorize("@ss.hasPermi('clothing:customization:add')")
    @Log(title = "定制管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCustomization sysCustomization)
    {
        return toAjax(sysCustomizationService.insertSysCustomization(sysCustomization));
    }

    /**
     * 修改定制管理
     */
//    @PreAuthorize("@ss.hasPermi('clothing:customization:edit')")
    @Log(title = "定制管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCustomization sysCustomization)
    {
        return toAjax(sysCustomizationService.updateSysCustomization(sysCustomization));
    }

    /**
     * 删除定制管理
     */
//    @PreAuthorize("@ss.hasPermi('clothing:customization:remove')"

    @Log(title = "定制管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysCustomizationService.deleteSysCustomizationByIds(ids));
    }

    /**
     * 获取测量所需参数
     * @param querySize
     * @return
     */
    @PostMapping("/getNeedSize")
    public SysCustomization getNeedSize(@RequestBody  querySize querySize){
        return sysCustomizationService.getNeedSize(querySize);
    }
}
